$(function(){
	
  // 请求列表
  get_question_list();
    function get_question_list(){
      var index = $(".load-more").attr("data-id");
      var question_type = $(".my-question-type a.cua").attr("data-id");
      if (index == "1") {index = ""};
      var token =  JSON.parse(localStorage.getItem('token'));
      var question_list_url= apitest+"/user/question?type="+question_type+"&token="+token+"&size=8&page="+index;
      var loading = '<div class="loading">加载中...</div>';
      $(".question-list-box").append(loading);
      $.get(question_list_url,function(data){
        },'json').error(function(data){
          var obj = $.parseJSON(data.responseText);
          layer.msg(obj.error_messages);
        }).success(function(data){
          $(".loading").remove();
          var obj = data.data;
          console.info(obj);
          var length = obj.length;
          var src = '';
          if (obj.length>7) {
                  $(".load-more").css("display","block")
                }else{
                  $(".load-more").css("display","none")
                }
          if (obj.length>0) {
            for(var i = 0;i < obj.length; i++){
              src +='<li>'
                src +='<div class="oh">'
                  src +='<a href="'+jumpUrl+'/question/'+obj[i].id+'" class="question-title">'+obj[i].title+'</a>'
                  src +='<span class="fr colorD font16">'+obj[i].post_category_name+'</span>'
                src +='</div>'
                src +='<div class="colorD font14">回答'
                  src +='<span class="colorC"> '+obj[i].comments_count+'</span> '
                  src +='<span class="font16">• </span>收藏'
                  src +='<span class="colorC"> '+obj[i].collects_count+'</span>'
                  src +='<span style="margin-left: 20px;">'+obj[i].created_at+'</span>'
                src +='</div>'
              src +='</li>'
            }
            $(".question-list-box").append(src);
          }else{
          var str ='<li class="textac"><span class="colorB">暂无数据</span></li>';
          $(".question-list-box").append(str);
        }
        });
    }
     // 加载更多
    $(document).on("click",".load-more",function(e){
      index = parseInt($(".load-more").attr("data-id"))+1;
      $(".load-more").attr("data-id",index);
      get_question_list();
    });


     // 加载更多
    $(document).on("click",".my-question-type a",function(e){
      $(".my-question-type a").removeClass('cua');
      $(this).addClass("cua");
      $(".question-list-box li").remove();
      $(".loading").remove();
      get_question_list();
    });
});



